<?php
define('_file_','delete_cat');
if ( !isGod() )
	if ( !getRights($mod,'full') )
		if ( !News_getAccessFile(_file_) )
		{
			showMsg('Không có quyền truy cập vào trang này này !','ex','center');
			die();
		}
$cid = getVar('cid',true);

if ( empty($cid) || $cid <= 0 )
	die('Dữ liệu không hợp lệ !');
	
$sql = "DELETE FROM category WHERE cid=" . $cid;
$link->execute($sql);

$sql = "select tid from topic where cid=$cid";
$rs = $link->execute($sql);
while ( !$rs->EOF )
{
	//xoa cac chu de thuoc cat
	$sql = "delete from topic where tid=" . $rs->fields('tid');
	$link->execute($sql);

	$sql = "select autoid,picture from article where tid=" . $rs->fields('tid');;
	$rs1 = $link->execute($sql);
	while ( !$rs1->EOF )
	{
		$sql = "DELETE FROM images WHERE imgid=" . $rs1->fields('picture');
		$link->execute($sql);
		//xoa tat ca cac bai viet thuoc ve topic nay
		$sql = "DELETE FROM article WHERE tid=" . $rs1->fields('autoid');
		$link->execute($sql);		
			
		$rs1->movenext();
	}
	$rs->movenext();
}

header("Location: admin.php?mod=$mod");
die();
?>